<template>
  <div>
    <el-dialog :title="title" :visible.sync="UploadOpen" width="500px" append-to-body>
      <el-upload
        ref="upload"
        :limit="1"
        accept=".jpg, .png, .xlsx, .xls, .pdf, .txt, .doc"
        :action="upload.url"
        :headers="upload.headers"
        :file-list="upload.fileList"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false">
        <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
        <el-button style="margin-left: 10px;" size="small" type="success" :loading="upload.isUploading" @click="submitUpload">上传到服务器</el-button>
        <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过500kb</div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <!--          <el-button type="primary" @click="submitForm">确 定</el-button>-->
        <el-button @click="cancel">关闭</el-button>
      </div>
    </el-dialog>
<!--    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" @submit.native.prevent>-->
<!--      <el-form-item label="日期" prop="groupDate">-->
<!--        <el-date-picker clearable size="small" style="width: 200px"-->
<!--                        v-model="queryParams.groupDate"-->
<!--                        type="date"-->
<!--                        value-format="yyyy-MM-dd"-->
<!--                        placeholder="选择日期"-->
<!--                        @change="handleQuery">-->
<!--        </el-date-picker>-->
<!--      </el-form-item>-->
<!--      <el-form-item>-->
<!--                <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>-->
<!--                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>-->
<!--      </el-form-item>-->
<!--    </el-form>-->

    <div>

      <el-row :gutter="10" class="mb8">
        <el-col :span="24">
<!--          <el-button style="background-color: #6a4cee;color: #d8dce5" @click="getMostNewData">获取最新数据</el-button>-->
          <el-button type="primary" @click="saveReport">保存</el-button>
<!--          <el-button type="success" @click="exportReport">导出</el-button>-->
        </el-col>

        <table class="table">
          <tr>
            <th :colspan="1" style="width: 20%">填表班</th>
            <th :colspan="2" style="width: 28%">信息项</th>
            <th :colspan="1">填报内容</th>
            <th :colspan="1">支撑材料</th>

          </tr>
          <tr>
            <th :rowspan="9">烧结工序</th>

            <th :colspan="2">产品名称</th>
            <td :colspan="1">{{ curData.productName }}</td>
            <td :rowspan="8">
              <el-button style="margin-left: 10px;" size="small" type="success"  @click="handleUpload()">上传附件</el-button>
            </td>

          </tr>
          <tr>
            <th :colspan="2">产品代码</th>
            <td :colspan="1">{{ curData.productCode }}</td>
          </tr>
          <tr>
            <th :colspan="2">工序产品生产能力（万吨/年）（主管部门批复产能）</th>
            <td :colspan="1" class="input">

              <el-input-number v-model="curData.productCapacity" :controls="false"
                               style="width: 100%"/>
            </td>
          </tr>
          <tr>
            <th :rowspan="4">烧结设施1</th>
            <th :colspan="1">设施名称</th>
            <td :colspan="1" class="input">
              <el-input v-model="curData.equip1Name" :controls="false"
                        style="width: 100%"/>
            </td>
          </tr>
          <tr>

            <th :colspan="1">设施规格</th>
            <td :colspan="1" class="input">
              <el-input v-model="curData.equip1Spec" :controls="false"
                        style="width: 100%"/>
            </td>
          </tr>
          <tr>

            <th :colspan="1">设施单位</th>
            <td :colspan="1" >
              {{curData.equip1Unit}}
            </td>
          </tr>
          <tr>

            <th :colspan="1">投运时间</th>
            <td :colspan="1" >
              {{curData.equip1Runtime}}
            </td>
          </tr>
          <tr>

            <th :colspan="2" :rowspan="2">说明</th>
            <td :colspan="1" class="input1">
              <span><span>本月正常生产</span><el-input  v-model="curData.productDay" :controls="false" style="width: 18%"/><span>天，停产</span>
              <el-input  v-model="curData.stopDay" :controls="false" style="width: 18%"/><span>天，检修</span>
              <el-input  v-model="curData.maintainDay" :controls="false" style="width: 18%"/><span>天</span></span>
            </td>
          </tr>


        </table>
      </el-row>
    </div>
  </div>
</template>

<script>


import {addEquip, updateEquip, getEquip, pageEquip} from '@/api/app/carbonEmission/equip'
import { getToken } from "@/utils/auth";
import {addUploadInfo} from "@/api/app/carbonEmission/uploadInfo";
import {fileToComponentName} from "@vue/cli-service/lib/commands/build/resolveWcEntry";
export default {
  name: 'ThreeStruggle',
  components: {},
  data() {
    return {
      dataList:[],
      curData:{

      },
      UploadOpen:false,
      title:'上传文件信息',
// 上传参数
      upload: {
        // 是否禁用上传
        isUploading: false,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url:process.env.VUE_APP_BASE_API + "/common/upload",
        // 上传的文件列表
        fileList: []
      },
      uploadInfo:{
        belong:'工序生产设施信息表',
        itemInfo:'',
        filePath:'',
        fileNameReal:'',
        fileNameShow:'',
        fileSize:'',
        delFlag:''
      },


      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 三班奋斗报表格数据
      threeStruggleList: [],
      // 弹出层标题

      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        groupDate: null,
        groupClasses: null,
        groupTeam: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      testValue: 1,


    }
  },
  async created() {

    this.getList()
  },
  methods: {



    /** 查询三班奋斗报列表 */
    getList() {
      this.loading = true
      pageEquip(this.queryParams).then(res => {
        this.dataList = res.data.rows
        this.total = res.data.total
        this.loading = false
        this.curData = this.dataList[0]

      })

    },

    saveReport(){
      updateEquip(this.curData).then(res => {
        this.msgSuccess('修改成功')
        this.open = false
        this.getList()
      })
    },

    exportReport() {

    },

    formatNumber(value) {
      if (typeof value === 'number' && isFinite(value)) {
        return value.toFixed(2)
      } else {
        return "***";
      }
    },

    /** 获取最新数据按钮 **/
    async getMostNewData() {
      let msgWait = this.$message({
        duration: 0,   // 设置为0就可以使永久停留
        type: 'warning',
        message: '正在获取最新数据，请不要关闭页面....',
      })
      updateMostData(this.queryParams).then(res => {
        msgWait.close()
        this.msgSuccess("获取最新数据成功！");
        this.getList()
      })
    },


    // 文件提交处理
    submitUpload() {
      this.$refs.upload.submit();
      //后台处理
      console.log("this.upload.fileList"+this.upload.fileList);
    },
// 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
// 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.isUploading = false;
      this.form.filePath = response.url;
      this.msgSuccess(response.msg);
      //可以提交后台
      console.log("提交文件信息至表");
      this.uploadInfo.filePath = fileList[0].response.data.fileName;
      this.uploadInfo.fileSize = fileList[0].size;
      this.uploadInfo.fileNameReal = fileList[0].name
      addUploadInfo(this.uploadInfo).then(res => {
        // this.msgSuccess('提交成功');
      })
    },
    cancel(){
      this.UploadOpen = false;
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,

      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },


    handleUpload(){
      //row 表示当前正要上传文件的行

      this.UploadOpen = true;
    }
  }
}
</script>

<style lang="scss" scoped>
.title {
  font-size: 24px;
  margin-bottom: 5px;
  text-align: center;
}

::v-deep .el-table {
  .el-table__header-wrapper th, .el-table__fixed-header-wrapper th {
    height: 30px;
  }

  .el-table__cell {
    padding: 0;
  }

  .selected {
    background-color: #00b2ff !important;
    color: #ffffff !important;
  }

  .unproduced {
    background-color: #ffaa00;
    color: #ffffff;
  }

  .producing {
    background-color: #ff6f00;
    color: #ffffff;
  }

  .producing-converter {
    background-color: #13d70e;
    color: #ffffff;
  }

  .producing-lf {
    background-color: #029c00;
    color: #ffffff;
  }

  .producing-caster {
    background-color: #036800;
    color: #ffffff;
  }

  .produced {
    .alarm {
      color: #ff0000;
      animation: alarm-animation 1s infinite;
    }
  }

  @keyframes alarm-animation {
    0%, 50% {
      //background-color: #ff0000;
      //color: #FFFFFF;
      color: #606266;
    }
    51%, 100% {
      //background-color: #FFFFFF;
      color: #ff0000;
    }
  }

  .hover-row {
    /*td {
      background-color: #ffffff !important;
    }*/

    .cell {
      color: #000000;
    }
  }
}

::v-deep .el-tabs__header {
  margin-bottom: 0px;
}

.table {
  table-layout: fixed;
  border-collapse: collapse;
  width: 100%;
  text-align: center;

  th, td {
    border: 1px solid #cccccc;
    padding: 8px 0;
    font-size: 16px;
  }

  th {
    background-color: #9c9c9c;
    color: #ffffff;
  }

  .input {
    padding: 0;

    ::v-deep {
      .el-input__inner {
        height: 44px;
        line-height: 44px;
        background-color: #ffa200;
        color: #ffffff;
        font-size: 16px;
        text-align: center;
      }

      .el-textarea__inner {
        background-color: #ffa200;
        color: #ffffff;
      }

      ::placeholder {
        color: #dddddd;
      }
    }
  }

  .input1 {
    //padding: 0;

    ::v-deep {
      .el-input__inner {
        //height: 44px;
        //line-height: 44px;
        background-color: #ffa200;
        color: #ffffff;
        font-size: 16px;
        text-align: center;
      }

      .el-textarea__inner {
        background-color: #ffa200;
        color: #ffffff;
      }

      ::placeholder {
        color: #dddddd;
      }
    }
  }
}

.ps {
  margin-top: 10px;
  font-size: 14px;

  span {
    margin-left: 10px;
    vertical-align: top;
  }

  .ps-icon {
    display: inline-block;
    width: 16px;
    height: 16px;
    vertical-align: top;
  }

  .unproduced {
    color: #ffaa00;

    .ps-icon {
      background-color: #ffaa00;
    }
  }

  .producing {
    color: #ff6f00;

    .ps-icon {
      background-color: #ff6f00;
    }
  }

  .producing-converter {
    color: #13d70e;

    .ps-icon {
      background-color: #13d70e;
    }
  }

  .producing-lf {
    color: #029c00;

    .ps-icon {
      background-color: #029c00;
    }
  }

  .producing-caster {
    color: #036800;

    .ps-icon {
      background-color: #036800;
    }
  }

  .produced {
    .ps-icon {
      background-color: #FFFFFF;
      border: 1px solid #000000;
    }
  }
}

.chart {
  height: 300px;
}

.chart2 {
  height: 400px;
}

.input-color {
  ::v-deep {
    .el-input__inner {
      background-color: #0015ff;
      color: #ffffff;
    }

    .el-textarea__inner {
      background-color: #0015ff;
      color: #ffffff;
    }

    ::placeholder {
      color: #dddddd;
    }
  }
}

.fill {
  ::v-deep .el-table__cell {
    padding: 0;

    .cell {
      padding: 0;
    }
  }
}
</style>
